/*
 * 1. Разбиение на компоненты связности. (<<<)
 * 2. Проверка на двудольность.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N_MAX	1000
#define M_MAX	1000000
#define DEBUG	1

struct Node {
	int x;
	Node *next;
};

struct adjlist {
	Node *first;
	Node *last;
	int size;
	int conn_sp_id;
	int visited;
};


void
pushback(struct adjlist *al, int x)
{
	Node *newnode;

	newnode = (Node *) malloc(sizeof (Node));
	newnode->x = x;
	newnode->next = NULL;
	if (!al->first)
		al->first = newnode;
	else
		al->last->next = newnode;
	al->last = newnode;
	al->size++;
}

void
free_al(struct adjlist *al)
{
	struct Node *n, *p;
	p = n = al->first;
	while (n) {
		n = n->next;
		free(p);
		p = n;
	}
}

void
listprint(struct Node *node)
{
	while (node) {
		printf("%d%s", node->x + 1, node->next ? " -> " : "\n");
		node = node->next;
	}
}

void
dfs(struct adjlist *al, const int n, const int vtx_start, const int conn_sp_id)
{
	int i;
	Node *node;

	al[vtx_start].conn_sp_id = conn_sp_id;
	al[vtx_start].visited    = 1;
	node = al[vtx_start].first;

	while (node) {
		if (al[node->x].conn_sp_id == 0)
			dfs(al, n, node->x, conn_sp_id);
		node = node->next;
	}
}

void
graph_div_on_conn_sp(struct adjlist *al, const int n)
{
	int space_num = 1;
	int i;

	for (i = 0 ; i < n ; ++i)
		if (al[i].conn_sp_id == 0)
			dfs(al, n, i, space_num++);
}

void
graph_print_by_conn_sp(struct adjlist *al, int n)
{
	int i = 0;
	int conn_sp = 0;

	while (i < n) {
		if (al[i].conn_sp_id > conn_sp)
			conn_sp = al[i].conn_sp_id;
		i++;
	}
	while (conn_sp) {
		i = 0;
		printf("connection space #%d: ", conn_sp);
		while (i < n) {
			if (al[i].conn_sp_id == conn_sp) {
				printf("%d ", i);
			}
			i++;
		}
		putchar('\n');
		conn_sp--;
	}
}

int
main(void)
{
	static struct adjlist AL[N_MAX];
	static char line[1024], *read_ptr;
	int i = 0, n = 0;
	int vtx_id, vtx_ref;

	while ((read_ptr = fgets(line, 1024, stdin))) {
		if (sscanf(read_ptr, "%d", &vtx_id) != 1)
			continue;
		n = vtx_id + 1 > n ? vtx_id + 1 : n;
		while (read_ptr = strchr(read_ptr, ' '), read_ptr) {
			if (sscanf(++read_ptr, "%d", &vtx_ref) != 1)
				break;
			pushback(&AL[vtx_id], vtx_ref);
			pushback(&AL[vtx_ref], vtx_id);
			n = vtx_ref + 1 > n ? vtx_ref + 1 : n;
			n = vtx_id + 1 > n ? vtx_id + 1 : n;
		}
	}
	fprintf(stderr, " : n=%d\n", n);
	for (i = 0 ; i < n ; ++i) {
		AL[i].visited = AL[i].conn_sp_id = 0;
	}

	graph_div_on_conn_sp(AL, n);
	graph_print_by_conn_sp(AL, n);

	for (i = 0 ; i < n ; ++i) {
		free_al(&AL[i]);
	}

	return (0);
}
